<template>

    <div>
        <div style="margin: 20px auto">
            <el-button type="primary" @click="postdlg">发布招聘</el-button>
        </div>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="name" label="岗位名称" width="250">
            </el-table-column>
            <el-table-column prop="salary_down" label="底薪" width="150">
            </el-table-column>
            <el-table-column prop="salary_up" label="最高薪水" width="150">
            </el-table-column>
            <el-table-column prop="tel" label="联系电话" width="250">
            </el-table-column>
            <el-table-column prop="intro" label="岗位介绍" width="300">
            </el-table-column>
            <el-table-column label="公司" width="120">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="find(scope.$index)"
                    >公司详情
                    </el-button
                    >

                    <el-dialog
                            title="公司详情"
                            :visible.sync="dialogVisible1"
                            width="30%"
                            :before-close="handleClose"

                    >
                        <span>

                            <div style="display:inline">
                                <label>公司名称</label>
                                <el-input
                                        v-model="form_new.name"
                                        style="margin-right: 40%;padding-bottom: 10px"
                                ></el-input>


                                <label>公司行业</label>
                                <el-input
                                        v-model="form_new.industry"
                                        style="margin-right: 40%;margin-top: 10px"
                                ></el-input>


                                <label>人员规模</label>
                                <el-input
                                        v-model="form_new.size"
                                        style="margin-right: 40%"
                                ></el-input>


                                <label>联系电话</label>
                                <el-input
                                        v-model="form_new.tel"
                                        style="margin-right: 40%"
                                ></el-input>


                                <label>公司评分</label>
                                <el-input
                                        v-model="form_new.grade"
                                        style="margin-right: 40%"
                                ></el-input>
                            </div>


                        </span>
                        <span slot="footer" class="dialog-footer">
                          <el-button @click="dialogVisible1 = false">取 消</el-button>
                          <el-button type="primary" @click="dialogVisible1 = false"
                          >确 定</el-button
                          >
                        </span>
                    </el-dialog>
                </template>
            </el-table-column>

            <el-table-column label="部门" width="120">
                <template slot-scope="scope">
                    <el-button type="warning" size="mini" @click="find1(scope.$index)"
                    >部门详情
                    </el-button
                    >
                    <el-dialog
                            title="部门详情"
                            :visible.sync="dialogVisible2"
                            width="30%"
                            :before-close="handleClose"
                    >
            <span>

              <div style="display:inline">
                <label>部门名称</label>
                <el-input
                        v-model="form.name"
                        style="margin-right: 40%;padding-bottom: 10px"
                ></el-input>


                <label>部门介绍</label>
                <el-input
                        v-model="form.intro"
                        style="margin-right: 40%;margin-top: 10px"
                ></el-input>


                </div>


            </span>
                        <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisible2 = false">取 消</el-button>
              <el-button type="primary" @click="dialogVisible2 = false"
              >确 定</el-button
              >
            </span>
                    </el-dialog>
                </template>
            </el-table-column>

            <el-table-column label="已投简历" width="120">
                <template slot-scope="scope">
                    <el-button type="danger" size="mini" @click="find2(scope.row)">简历列表</el-button>

                </template>
            </el-table-column>

        </el-table>


        <!--        发布招聘岗位-->
        <el-dialog
                :title="title"
                :visible.sync="dialogVisiblePost"
                width="80%">
            <div>
                <el-form :model="recruit" ref="empForm">
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="岗位名称:" prop="name">
                                <el-input size="mini" style="width: 150px" prefix-icon="el-icon-edit"
                                          v-model="recruit.name"
                                          placeholder="请输入岗位名称"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="底薪:" prop="salaryDown">
                                <el-input size="mini" style="width: 150px" prefix-icon="el-icon-edit"
                                          v-model="recruit.salaryDown"
                                          placeholder="请输入底薪"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="最高薪资:" prop="salaryUP">
                                <el-input size="mini" style="width: 150px" prefix-icon="el-icon-edit"
                                          v-model="recruit.salaryUP"
                                          placeholder="请输入最高薪资"></el-input>
                            </el-form-item>
                        </el-col>

                        <el-col :span="7">
                            <el-form-item label="电话:" prop="tel">
                                <el-input size="mini" style="width: 200px" prefix-icon="el-icon-edit"
                                          v-model="recruit.tel"
                                          placeholder="请输入电话"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <!--                    第二行-->
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="链接:" prop="testLink">
                                <el-input size="mini" style="width: 150px" prefix-icon="el-icon-edit"
                                          v-model="recruit.testLink"
                                          placeholder="请输入链接"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="公司id:" prop="companyId">
                                <el-input size="mini" style="width: 150px" prefix-icon="el-icon-edit"
                                          v-model="recruit.company.id"
                                          placeholder="请输入公司id"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="部门id:" prop="departmentId">
                                <el-input size="mini" style="width: 150px" prefix-icon="el-icon-edit"
                                          v-model="recruit.department.id"
                                          placeholder="请输入部门id"></el-input>
                            </el-form-item>
                        </el-col>

                    </el-row>

                    <el-form-item label="岗位介绍:" prop="intro" style="width: 92%">
                        <el-input
                                type="textarea"
                                :rows="8"
                                placeholder="请输入内容"
                                v-model="recruit.intro">
                        </el-input>
                    </el-form-item>

                </el-form>


            </div>

            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisiblePost = false">取 消</el-button>
                <el-button type="primary" @click="RecPost">确 定</el-button>
            </span>
        </el-dialog>

        <!--        简历列表-->
        <el-dialog
                :title="title"
                :visible.sync="dialogVisible3"
                width="80%">
            <div>
                <el-table :data="resume" style="width: 100%">


                    <el-table-column
                            type="selection"
                            width="55">
                    </el-table-column>

                    <el-table-column
                            prop="archive.name"
                            fixed
                            align="left"
                            label="姓名"
                            width="90">
                    </el-table-column>
                    <el-table-column
                            prop="archive.sex"
                            align="left"
                            label="性别"
                            width="90">
                    </el-table-column>
                    <el-table-column
                            prop="archive.age"
                            align="left"
                            label="年龄"
                            width="90">
                    </el-table-column>
                    <el-table-column
                            prop="archive.mail"
                            align="left"
                            label="邮箱"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            prop="archive.intro"
                            align="left"
                            label="介绍"
                            width="90">
                    </el-table-column>
                    <el-table-column
                            prop="archive.date"
                            align="left"
                            label="入职时间"
                            width="220">
                    </el-table-column>
                    <el-table-column
                            prop="archive.policy"
                            align="left"
                            label="政治面貌"
                            width="90">
                    </el-table-column>
                    <el-table-column
                            prop="archive.area"
                            align="left"
                            label="住址"
                            width="150">
                    </el-table-column>
                    <el-table-column
                            prop="archive.degree"
                            align="left"
                            label="学位"
                            width="90">
                    </el-table-column>
                    <el-table-column
                            prop="archive.school"
                            align="left"
                            label="毕业院校"
                            width="150">
                    </el-table-column>
                    <el-table-column
                            prop="archive.major"
                            align="left"
                            label="专业"
                            width="150">
                    </el-table-column>


                    <el-table-column
                            fixed="right"
                            prop="status"
                            label="审批状态"
                            width="80"
                            :filters="[{ text: '未通过', value: '未通过' }, { text: '已通过', value: '已通过' }, { text: '已入职', value: '已入职' },{ text: '已拒绝', value: '已拒绝' }, { text: '待审核', value: '待审核' }, { text: '已接受', value: '已接受' }]"
                            :filter-method="filterTag"
                            filter-placement="bottom-end">

                        <template slot-scope="scope">

                            <el-tag>{{scope.row.status == "未通过"? '未通过' : (scope.row.status == '已通过' ?
                                '已通过':(scope.row.status ==
                                '已入职' ? '已入职' :(scope.row.status == '已拒绝' ? '已拒绝' :(scope.row.status == '待审核' ?
                                '待审核' :
                                (scope.row.status == '已接受' ?
                                '已接受' :
                                '')))))}}
                            </el-tag>

                        </template>
                    </el-table-column>

                    <el-table-column
                            fixed="right"
                            width="200"
                            label="操作">
                        <template slot-scope="scope">
                            <!--                            <el-button @click="showEditEmpView(scope.row)" style="padding: 3px" size="mini">编辑</el-button>-->
                            <el-button @click="showMoreInfo(scope.row)" style="padding: 3px" size="mini" type="primary">
                                查看更多资料
                            </el-button>
                            <el-button @click="agree(scope.row)" style="padding: 3px" size="mini">{{scope.row.status=="已接受"?'入职':'通过'}}</el-button>
                            <el-button @click="refuse(scope.row)" style="padding: 3px" size="mini">拒绝</el-button>
                        </template>
                    </el-table-column>

                </el-table>


            </div>

            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible3 = false">取 消</el-button>
                <el-button type="primary" @click="RecPost">确 定</el-button>
            </span>
        </el-dialog>


        <!--        高级员工资料-->
        <el-dialog

                :visible.sync="dialogVisibleInfo"
                width="80%">
            <div>
                <el-form :model="ra" ref="empForm">
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="id:" prop="id">
                                <div>{{ra.id}}</div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="姓名:" prop="name">
                                <div>{{ra.name}}</div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="性别:" prop="sex">
                                <div>{{ra.sex}}</div>
                            </el-form-item>
                        </el-col>

                        <!--                        <el-col :span="7">-->
                        <!--                            <el-form-item label="入职时间:" prop="date">-->
                        <!--                                <div>{{ra.date}}</div>-->
                        <!--                            </el-form-item>-->
                        <!--                        </el-col>-->
                    </el-row>
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="学位:" prop="degree">
                                <div>{{ra.degree}}</div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="政治面貌:" prop="policy">
                                <div>{{ra.policy}}</div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="电子邮箱:" prop="email">
                                <div>{{ra.mail}}</div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="联系地址:" prop="area">
                                <div>{{ra.area}}</div>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="年龄:" prop="age">
                                <div>{{ra.age}}</div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5">
                            <el-form-item label="电话号码:" prop="tel">
                                <div>{{ra.tel}}</div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="毕业院校:" prop="school">
                                <div>{{ra.school}}</div>

                            </el-form-item>
                        </el-col>
                        <el-col :span="7">
                            <el-form-item label="专业名称:" prop="major">
                                <div>{{ra.major}}</div>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-form-item label="个人介绍:" prop="intro" style="width: 92%">
                        <div>{{ra.intro}}</div>
                    </el-form-item>

                    <el-form-item label="特长介绍:" prop="talents" style="width: 35%">

                        <el-table
                                :data="ra.talents"
                                style="width: 100%">
                            <el-table-column
                                    prop="name"
                                    label="特长项目"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="level"
                                    label="水平">
                            </el-table-column>
                        </el-table>

                    </el-form-item>

                    <el-form-item label="历史职位:" prop="positions" style="width: 97%">

                        <el-table
                                :data="ra.positions"
                                style="width: 100%">
                            <el-table-column
                                    prop="name"
                                    label="职位名称"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="salary"
                                    label="薪资"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="privilege"
                                    label="特权"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="department.name"
                                    label="部门"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="start"
                                    label="开始时间"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="end"
                                    label="结束时间"
                                    width="200">
                            </el-table-column>
                        </el-table>

                    </el-form-item>

                    <el-form-item label="员工事迹:" prop="deeds" style="width: 97%">

                        <el-table
                                :data="ra.deeds"
                                style="width: 100%">
                            <el-table-column
                                    prop="name"
                                    label="名称"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="role"
                                    label="角色"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="details"
                                    label="明细"
                                    width="400">
                            </el-table-column>
                            <el-table-column
                                    prop="start"
                                    label="开始时间"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="end"
                                    label="结束时间"
                                    width="200">
                            </el-table-column>
                        </el-table>

                    </el-form-item>

                    <el-form-item label="相关评价:" prop="evaluates" style="width: 97%">

                        <el-table
                                :data="ra.evaluates"
                                style="width: 100%">
                            <el-table-column
                                    prop="role"
                                    label="角色"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="commenter.archive.name"
                                    label="评论员"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="grade"
                                    label="评分"
                                    width="200">
                            </el-table-column>
                            <el-table-column
                                    prop="content"
                                    label="评价"
                                    width="600">
                            </el-table-column>
                        </el-table>

                    </el-form-item>


                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
<!--                <el-button @click="dialogVisibleInfo = false">取 消</el-button>-->
                <!--                <el-button type="primary" @click="doAddEmp">确 定</el-button>-->
            </span>
        </el-dialog>

        <!--        入职资料编辑-->
        <el-dialog

                :visible.sync="dialogVisibleEntry"
                width="80%">
            <div>
                <H2>填写入职信息</H2>
                <div>
                    <el-form :model="entry" ref="empForm">
                        <el-row>
                            <!--                            <el-col :span="6">-->
                            <!--                                <el-form-item label="用户id:" prop="id">-->
                            <!--                                    <el-input disabled size="mini" style="width: 150px" prefix-icon="el-icon-edit"-->
                            <!--                                              v-model="entry.id"-->
                            <!--                                              placeholder="请输入用户id"></el-input>-->
                            <!--                                </el-form-item>-->
                            <!--                            </el-col>-->
                            <el-col :span="6">
                                <el-form-item label="部门id:" prop="departmentId">
                                    <el-input size="mini" style="width: 150px" prefix-icon="el-icon-edit"
                                              v-model="entry.department.id"
                                              placeholder="请输入部门id"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="职位名称:" prop="name">
                                    <el-input size="mini" style="width: 200px" prefix-icon="el-icon-edit"
                                              v-model="entry.name"
                                              placeholder="请输入职位名称"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="薪资:" prop="salary">
                                    <el-input size="mini" style="width: 150px" prefix-icon="el-icon-edit"
                                              v-model="entry.salary"
                                              placeholder="请输入薪资"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="6">
                                <el-form-item label="特权:" prop="privilege">
                                    <el-input size="mini" style="width: 200px" prefix-icon="el-icon-edit"
                                              v-model="entry.privilege"
                                              placeholder="请输入特权（”管理“或不填）"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="5">
                                <el-form-item label="开始时间:" prop="start">
                                    <el-input size="mini" style="width: 200px" prefix-icon="el-icon-edit"
                                              v-model="entry.start"
                                              placeholder="请输入开始时间"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                    </el-form>
                </div>

            </div>

            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisibleEntry = false">取 消</el-button>
                <el-button type="primary" @click="doAddEntry">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
    import axios from "axios";
    import {Message} from "element-ui";

    export default {
        name: "HrMng",
        data() {
            return {
                tableData: [],
                companys: [],
                departments: [],
                form_new: {
                    name: "",
                    industry: "",
                    size: "",
                    grade: "",
                    tel: "",
                },
                form: {
                    name: "",
                    intro: "",
                },
                dialogVisible1: false,
                dialogVisible2: false,
                dialogVisible3: false,
                dialogVisiblePost: false,
                dialogVisibleInfo: false,
                dialogVisibleEntry: false,


                title: '',
                // emp: [],

                recruit: {
                    name: '',
                    salaryDown: null,
                    salaryUP: null,
                    tel: '',
                    testLink: '',
                    intro: '',
                    company: {
                        id: null,
                    },
                    department: {
                        id: null,
                    }
                },
                resumes: [],
                resume: {
                    uid: null,
                    wid: null,
                    status: "",
                    archive: {
                        id: null,
                        name: "",
                        sex: "",
                        mail: "xxx@abc.com",
                        intro: "xxxxxxx",
                        date: "2021-06-15T04:51:31.000+00:00",
                        pub: true,
                        tel: "xxxxxxxxx",
                        policy: "党员",
                        area: "xx",
                        degree: "学士",
                        school: "xx",
                        major: "xx",
                        age: 0,
                        talents: [],
                        positions: [],
                        deeds: [],
                        evaluates: []
                    }
                },
                ra: {
                    id: null,
                    name: "",
                    sex: "",
                    mail: "xxx@abc.com",
                    intro: "xxxxxxx",
                    date: "2021-06-15T04:51:31.000+00:00",
                    pub: true,
                    tel: "xxxxxxxxx",
                    policy: "党员",
                    area: "xx",
                    degree: "学士",
                    school: "xx",
                    major: "xx",
                    age: 0,
                    talents: [],
                    positions: [],
                    deeds: [],
                    evaluates: []
                },
                entry: {
                    // id: null,
                    department: {
                        id: null
                    },
                    name: "",
                    salary: null,
                    privilege: null,
                    start: "",
                },
                currentData: {},
            };
        },
        created() {
            let url = '/hr/mng/get';

            //替换成当前的cid
            let cid = JSON.parse(window.sessionStorage.getItem("currentCid"));

            this.getRequest(url, {'cid': cid}).then((data) => {
                // console.log(data);
                if (data) {
                    // console.log(data.data.wanteds);

                    data.data.wanteds.forEach((item) => {

                        this.tableData.push({
                            wid: item.id,
                            name: item.name,
                            salary_down: item.salaryDown,
                            salary_up: item.salaryUP,
                            tel: item.tel,
                            intro: item.intro,
                        });
                        this.companys.push(item.company);
                        this.departments.push(item.department);

                    });
                    // console.log(this.companys);
                    // console.log(this.departments);
                }
            });
        },
        methods: {
            handleEdit(index, row) {
                // console.log(index, row);
            },
            handleClose(done) {
                this.dialogVisible1 = false;
                this.dialogVisible2 = false;
                // this.$confirm("确认关闭？")
                //     .then((_) => {
                //         done();
                //     })
                //     .catch((_) => {
                //     });
            },
            find(index) {
                // console.log(index);
                this.dialogVisible1 = true;
                // console.log(this.companys);

                this.form_new.name = this.companys[index].name;
                this.form_new.industry = this.companys[index].industry;
                this.form_new.grade = this.companys[index].grade;
                this.form_new.tel = this.companys[index].tel;
                this.form_new.size = this.companys[index].size;
            },
            find1(index) {
                // console.log(index);
                this.dialogVisible2 = true;
                // console.log(this.companys);

                // console.log(this.departments[index].intro);
                this.form.name = this.departments[index].name;
                this.form.intro = this.departments[index].intro;
            },
            // 简历列表
            find2(data) {
                // console.log(data);
                this.dialogVisible3 = true;
                this.title = '简历列表';

                this.resume = [];

                let url = '/hr/mng/status/get';
                let cid = JSON.parse(window.sessionStorage.getItem("currentCid"));

                this.getRequest(url, {'wid': data.wid, 'cid': cid}).then(resp => {

                    resp.data.U_Ws.forEach(i => {
                        this.resume.push(i);
                    })

                    // console.log(999999);
                    // console.log(this.resume);

                });

            },
            postdlg() {
                this.title = '发布招聘';
                this.dialogVisiblePost = true;
            },
            RecPost() {
                let url = 'hr/mng/post';
                //替换成当前的cid
                let cid = JSON.parse(window.sessionStorage.getItem("currentCid"));

                // this.postRequest(url, {'cid': cid}).then((data) => {
                //     console.log(data);
                //
                // });

                this.dialogVisiblePost = false;
                // console.log(this.recruit);

                return axios({
                    method: 'post',
                    url: `${url}`,
                    params: {'cid': cid},
                    data: this.recruit,
                })
                //     .then((data) => {
                //     console.log(data);
                //
                // });

            },
            // 过滤器
            filterTag(value, row) {
                return row.status === value;
            },
            showMoreInfo(data) {

                // this.title = '更多员工信息';
                this.resume = data;
                this.ra = data.archive;

                this.dialogVisibleInfo = true;
            },
            agree(data) {

                if (data.status == "待审核") {

                    let url = '/rec/modify';
                    return axios({
                        method: 'post',
                        url: `${url}`,
                        params: {
                            'uid': data.uid,
                            'wid': data.wid,
                            'status': "已通过",
                        }
                    })

                } else if (data.status == "已接受") {
                    // console.log(data);
                    this.currentData = data;
                    // console.log(this.currentData);
                    this.dialogVisibleEntry = true;
                }else{
                    Message.error({message: '无效操作!'})
                }


            },
            refuse(data) {
                if (data.status == "待审核") {

                    let url = '/rec/modify';
                    return axios({
                        method: 'post',
                        url: `${url}`,
                        params: {
                            'uid': data.uid,
                            'wid': data.wid,
                            'status': "未通过",
                        }
                    })

                }else{
                    Message.error({message: '无效操作!'})
                }
            },
            doAddEntry() {
                this.dialogVisibleEntry = false;

                let url = '/rec/modify';
                return axios({
                    method: 'post',
                    url: `${url}`,
                    params: {
                        'uid': this.currentData.uid,
                        'wid': this.currentData.wid,
                        'status': "已入职",
                    },
                    data: this.entry,
                })
            }
        },
    };
</script>

<style scoped>
</style>